package com.huike.pmps.controller;

import com.huike.pmps.model.constants.GlobalConstants;
import com.huike.pmps.model.dto.common.PageInfo;
import com.huike.pmps.model.entity.Member;
import com.huike.pmps.model.entity.SupplierSettlementDetail;
import com.huike.pmps.model.vo.Result;
import com.huike.pmps.service.SupplierSettlementDetailService;
import com.huike.pmps.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 作者：谌贵斌(黑桃K)
 * 日期: 2888-08-08
 * 老师QQ: 272488352
 * 官方QQ交流群: 377748272
 * 刀客程序员官网：http://www.daoke360.com
 * 刀客程序员淘宝旗舰店：https://daoke360.taobao.com/
 */
@RestController
@RequestMapping("/api/supplier_settlement_details")
@Api(tags = "PO课程-供应商-结算管理")
@Slf4j
public class SupplierSettlementDetailController {
    @Autowired
    SupplierSettlementDetailService supplierSettlementDetailService;

    @ApiOperation(value = "根据课程供应商主键ID生成结算清单", httpMethod = "POST")
    @PostMapping
    Result insertSupplierSettlementDetail(String ids) {
        return supplierSettlementDetailService.insertSupplierSettlementDetail(ids);
    }

    @ApiOperation(value = "根据主键ID删除单条记录", httpMethod = "DELETE")
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id) {
        return supplierSettlementDetailService.deleteById(id);
    }

    @ApiOperation(value = "根据主键ID更新记录", httpMethod = "PUT")
    @PutMapping
    public Result updateById(SupplierSettlementDetail supplierSettlementDetail) {
        return supplierSettlementDetailService.updateById(supplierSettlementDetail);
    }

    @ApiOperation(value = "供应商结算总表", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "po", value = "po单号", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "customerName", value = "客户名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "regionName", value = "战区", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "provinceName", value = "省份名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "courseName", value = "课程名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "courseChargeName", value = "课程编导", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "supplierName", value = "供应商名称", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "paymentStateName", value = "支付状态", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "taxPoint", value = "税点", paramType = "query", dataType = "String")

    })
    @GetMapping("/settlement_list")
    public Result selectByCondition(HttpServletRequest request, PageInfo pageInfo, String po, String customerName,
                                    String regionName, String provinceName, String courseName, String courseChargeName,
                                    String supplierName, Integer poCourseId,String paymentStateName,String taxPoint) {
        //从请求头中获取token
        Member member = (Member) request.getSession().getAttribute(TokenUtil.getToken(request));
        return supplierSettlementDetailService.selectByCondition(member,pageInfo, po, customerName, regionName,
                provinceName, courseName, courseChargeName, supplierName,poCourseId,paymentStateName,taxPoint);
    }
}
